package impl

import "gitee.com/go-course/go8/projects/devcloud/cmdb/apps/host"

func NewHostSet() *HostSet {
	return &HostSet{
		Items: []*Host{},
	}
}

type HostSet struct {
	Total int64
	Items []*Host
}

func (h *HostSet) HostSet() *host.HostSet {
	set := host.NewHostSet()
	for i := range h.Items {
		item := h.Items[i]
		ins := host.NewDefaultHost()
		ins.Resource.Meta.ResourceId = item.ResourceId
		ins.Spec = item.Spec
		set.Add(ins)
	}
	return set
}

func NewHost(h *host.Host) *Host {
	return &Host{
		ResourceId: h.Resource.Meta.ResourceId,
		Spec:       h.Spec,
	}
}

// 构造符合数据库映射逻辑的对象
type Host struct {
	ResourceId string `json:"resource_id"`
	*host.Spec
}

func (i *Host) TableName() string {
	return "resource_host"
}
